﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using PollSystem;

namespace PollSystemService
{
    public class PollSystemService : IPollSystemService
    {
        public List<string> GetQuestions()
        {
            List<string> questions = new List<string>();
            questions = PollSystem.PollSystem.GetQuestions();
            return questions;
        }

        public List<string> GetAnswers(string questionID)
        {
            int id = int.Parse(questionID) + 1;
            List<string> answers = new List<string>();
            answers = PollSystem.PollSystem.GetAnswers(id);
            return answers;
        }

        public List<Answer> Vote(Vote vote)
        {
            int questionID = vote.QuestionID;
            string answer = vote.Answer;
            List<Answer> votes = new List<Answer>();
            string question;
            Dictionary<string, int> questionVotes = PollSystem.PollSystem.Vote(questionID+1,answer, out question);
            foreach (var item in questionVotes)
            {
                Answer newAnswer = new Answer();
                newAnswer.AnswerText = item.Key;
                newAnswer.AnswerCount = item.Value;
                newAnswer.Question = question;
                votes.Add(newAnswer);
            }
            return votes;
        }
    }
}
